class OceanBaseRestoreService:
    def __init__(self, config):
        self.conn = OBConnection(config)
        
    def restore_database(self, backup_id, point_in_time=None):
        """
        执行数据库恢复
        :param backup_id: 备份集ID
        :param point_in_time: 时间点恢复（格式：'2023-01-01 12:00:00'）
        """
        backup_info = self._get_backup_info(backup_id)
        
        if point_in_time:
            self._recover_to_time(backup_info, point_in_time)
        else:
            self._restore_full(backup_info)
            
    def _restore_full(self, backup_info):
        """全量恢复"""
        cmd = f"ALTER SYSTEM RESTORE {backup_info['db_name']} FROM '{backup_info['path']}'"
        self._execute_ob_cmd(cmd)
        
    def _recover_to_time(self, backup_info, target_time):
        """时间点恢复"""
        cmd = f"""
        ALTER SYSTEM RECOVER DATABASE {backup_info['db_name']} 
        UNTIL TIME '{target_time}'
        USING BACKUP '{backup_info['path']}'
        """
        self._execute_ob_cmd(cmd)